package com.example.nationmobile;

import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public class SettingActivity extends Activity implements OnClickListener{

	
	private TextView txt_daytime;
	private FrameLayout Img_home,Img_opinion,Img_mul,Img_favorite,Img_setting; 
	
	private LinearLayout Lay_Tec,Lay_Adver,lay_mainsetting;
	private View lay_menusetting,lay_menusetting2;
	
	private int current_menu;
	
	private WebView WebView,WebView2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}
		
		Log.e("evt", "====================onCreate====================");
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_setting);
		
		
		//==============Tab=====================
				Img_home=(FrameLayout)findViewById(R.id.Img_home);
				Img_opinion=(FrameLayout)findViewById(R.id.Img_opinion);
				Img_mul=(FrameLayout)findViewById(R.id.Img_mul);
				Img_favorite=(FrameLayout)findViewById(R.id.Img_favorite);
				Img_setting =(FrameLayout)findViewById(R.id.Img_setting);
				
				Lay_Tec=(LinearLayout)findViewById(R.id.Lay_Tec);
				Lay_Adver=(LinearLayout)findViewById(R.id.Lay_Adver);
						
				Lay_Tec.setOnClickListener(this);
				Lay_Adver.setOnClickListener(this);
				
				Img_home.setOnClickListener(this);
				Img_opinion.setOnClickListener(this);
				Img_mul.setOnClickListener(this);
				Img_favorite.setOnClickListener(this);
				//Img_setting .setOnClickListener(this);
				
		
				
				
				WebView2 = (WebView) findViewById(R.id.webView2);
			//=======================View========================
				lay_mainsetting=(LinearLayout)findViewById(R.id.laymainsetting);
				lay_menusetting=(View)findViewById(R.id.lay_menusetting);
				lay_menusetting2=(View)findViewById(R.id.lay_menusetting2);
				
				lay_menusetting.setVisibility(View.INVISIBLE);
				lay_menusetting2.setVisibility(View.INVISIBLE);
				lay_mainsetting.setVisibility(View.VISIBLE);
				
				current_menu=0;
				
				
				
				WebView = (WebView) findViewById(R.id.webView1);
				WebView.getSettings().setJavaScriptEnabled(true);
				WebView.setInitialScale(100);
				WebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
			    WebView.loadUrl("http://www.nationmultimedia.com/new/setting/support.html");
				
				
			    WebView2.getSettings().setJavaScriptEnabled(true);
				WebView2.setInitialScale(100);
				WebView2.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
				WebView2.loadUrl("http://www.nationmultimedia.com/new/setting/advertising.html");
		    //==========================webView=====================
				
				//WebView.setInitialScale(1);
				
}


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		if(v.getId()==R.id.Img_home)
		{
			finish();	
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		
		if(v.getId()==R.id.Img_mul)
		{
			finish();	
			startActivityForResult(new Intent(SettingActivity.this,MulActivity.class), 0);
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		
		if(v.getId()==R.id.Img_favorite)
		{
			finish();	
			startActivityForResult(new Intent(SettingActivity.this,FavoritesActivity.class), 0);
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		if(v.getId()==R.id.Img_opinion)
		{
			finish();	
			startActivityForResult(new Intent(SettingActivity.this,OpinionActivity.class), 0);
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		
		
		
		
		if(v.getId()==R.id.Lay_Adver);
		{
			Log.e("NT", "Lay_Adver");
		   
			current_menu=1;
			lay_menusetting.setVisibility(View.INVISIBLE);
			lay_menusetting2.setVisibility(View.VISIBLE);
			lay_mainsetting.setVisibility(View.INVISIBLE);
			
			
			
		}
		
		if(v.getId()==R.id.Lay_Tec)
		{
			Log.e("NT", "Lay_Tec");
			current_menu=1;
			lay_menusetting.setVisibility(View.VISIBLE);
			lay_menusetting2.setVisibility(View.INVISIBLE);
			lay_mainsetting.setVisibility(View.INVISIBLE);
			
		}
		
	}

	public boolean onKeyDown( int keyCode, KeyEvent event ) {

	    if ( keyCode == KeyEvent.KEYCODE_BACK ) {
	    	
	    	if(current_menu==0)
	    	{
	    		WebView=null;
	    		finish();
	    	}
	    	else if(current_menu==1)
	    	{
	    		lay_menusetting2.setVisibility(View.INVISIBLE);
	    		lay_menusetting.setVisibility(View.INVISIBLE);
				lay_mainsetting.setVisibility(View.VISIBLE);
				current_menu=0;
	    	}
	    	
	    	
	    	return true;
	    }

	    return super.onKeyDown(keyCode, event);
	}
	
	
	
	
}
